package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.SignActivityService;
import com.ddwl.goods.service.SignConfigService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.SignActivityBo;
import com.ddwl.schema.bo.goods.SignConfigBo;
import com.ddwl.schema.bo.goods.SignConfigEnableBo;
import com.ddwl.schema.bo.goods.SignConfigPageBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.SignActivityVo;
import com.ddwl.schema.vo.goods.SignConfigVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author hemiaojun
 * @Date 2020/10/19 14:40
 */
@RestController
@RequestMapping("/sign")
@Api(tags = "签到配置")
public class SignConfigController extends BaseController {

    @Resource
    private SignActivityService signActivityService;
    @Resource
    private SignConfigService signConfigService;

    @PostMapping("/activity/add")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("新增签到活动")
    public RestVo<SignActivityVo> addSignActivity(@RequestBody(required = false) SignActivityBo bo){
        return RestVo.ok(signActivityService.add(bo));
    }

    @PostMapping("/activity/enableOrDisable")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("签到活动启用或禁用")
    public RestVo enableOrDisable(@RequestBody SignActivityBo bo){
        signActivityService.enableOrDisable(bo);
        return RestVo.ok();
    }

    @GetMapping("/activity/getSignActivity")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE,BaseEnum.ProductEnum.FENXIAO,BaseEnum.ProductEnum.MALL})
    @ApiOperation("获取签到活动")
    public RestVo<SignActivityVo> getSignActivity(){
        return RestVo.ok(signActivityService.get());
    }

    @PostMapping("/config/add")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("新增签到规则")
    public RestVo<SignConfigVo> addSignConfig(@RequestBody @Valid SignConfigBo bo){
        return RestVo.ok(signConfigService.add(bo));
    }

    @PostMapping("/config/update")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("修改签到规则")
    public RestVo updateSignConfig(@RequestBody @Valid SignConfigBo bo){
        signConfigService.update(bo);
        return RestVo.ok();
    }

    @DeleteMapping("/config/{configId}")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("删除签到规则")
    public RestVo deleteSignConfig(@PathVariable("configId") String configId){
        signConfigService.delete(configId);
        return RestVo.ok();
    }

    @GetMapping("/config/{configId}")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("获取签到规则")
    public RestVo<SignConfigVo> getSignConfig(@PathVariable("configId") String configId){
        return RestVo.ok(signConfigService.get(configId));
    }

    @PostMapping("/config/page")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("签到规则分页")
    public RestVo<PageVo<SignConfigVo>> page(@RequestBody PageBo<SignConfigPageBo> bo){
        return RestVo.ok(signConfigService.page(bo));
    }

    @PostMapping("/config/enableOrDisable")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("签到规则启用或禁用")
    public RestVo enableOrDisable(@RequestBody @Valid SignConfigEnableBo bo){
        signConfigService.enableOrDisable(bo);
        return RestVo.ok();
    }

}
